package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import view.StatisticPanel;
import model.StatisticTableModel;
import model.UICommand;

public class StatisticController implements ActionListener {
	private StatisticTableModel tableModel;
	private StatisticPanel view;

	public StatisticController(StatisticTableModel tableModel) {
		this.tableModel = tableModel;
		this.view = new StatisticPanel(tableModel, this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String cmd = e.getActionCommand();
		switch (cmd) {
		case UICommand.STATISTIC_CMD:
			String sql = view.getSql();
			tableModel.loadData(sql);
			view.setTextNBill(tableModel.getRowCount());
			break;
		case UICommand.RELOAD_CMD:
			tableModel.loadData(null);
			break;
		}
	}

	public JPanel getView() {
		return this.view;
	}

}
